
var todayProvince = "西藏";
var todayCity = "拉萨";
var sms_url = "https://api.rxb.ink"
function check() {
	document.querySelector("#myCheck").checked = true;
	document.getElementById('fwtc').style.display = 'none';
}

function uncheck() {
	document.querySelector("#myCheck").checked = false;
	document.getElementById('fwtc').style.display = 'none';
}
/**选择性别添加颜色 */
function chooseSex1() {
	$('.male').addClass('active1');
	$('#sex').val(1);
	$('.female').removeClass('active2')
}
function chooseSex2() {
	$('.female').addClass('active2');
	$('#sex').val(2);
	$('.male').removeClass('active1')
}
//下拉框选中改变颜色
$(function () {
	var unSelected = "#999999";
	var selected = "#333333";
	$("select").css("color", unSelected);
	$("option").css("color", selected);
	$("select").change(function () {
		var selItem = $(this).val();
		if (selItem == $(this).find('option:first').val()) {
			$(this).css("color", unSelected);
		} else {
			$(this).css("color", selected);
		}
	});
});


$(function () {
	var page_id = $('#page_id').val();
})
var phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;//手机号正则
var count = 60; //间隔函数，1秒执行
var InterValObj1; //timer变量，控制时间
var curCount1;//当前剩余秒数
/*第一*/
function sendMessage() {

	curCount1 = count;
	var mobile = $.trim($('#mobile').val());

	if (!phoneReg.test(mobile)) {
		layer.msg("请输入有效的手机号码");
		return false;
	}
	//设置button效果，开始计时
	var page_id = $('#page_id').val();
	$("#btnSendCode1").attr("disabled", "true");
	$("#btnSendCode1").val(+curCount1 + "秒再获取");
	var data = {
		mobile: mobile,
		type: 3,
		api_url: '/api/sms/sendsms',
		channelId: 52,
	}
	$.ajax({

		type: "POST",                      //请求类型
		url: 'http://baichuanguanggao.nas/ZhaoYangPage/sendMsg',
		data: JSON.stringify(data),
		jsonp: "callback",
		dataType: "JSON",                 //返回的数据类型
		contentType: "application/json",
		// contentType: false,               // 设为false，让jQuery不要自动设置Content-Type
		// processData: false,  
		success: function (Message) {
			if (Message.code == 200) {
				layer.open({ content: '短信验证码已发送', skin: 'msg', time: 2 });
				layer.msg('短信验证码已发送');
				//倒计时
				$("#btnSendCode1").attr("disabled", "true");
				$("#btnSendCode1").val(+curCount1 + "秒再获取");
				InterValObj1 = window.setInterval(SetRemainTime1, 1000);
			} else if (Message.code == 202) {
				layer.open({ content: '该用户已经提交过申请！', skin: 'msg', time: 2 });
				//倒计时
				if (Message.msg != null) {
					layer.msg('你今天的手机验证码获取上限');
				}
				$("#btnSendCode1").attr("disabled", "true");
				$("#btnSendCode1").val(+curCount1 + "秒再获取");
				InterValObj1 = window.setInterval(SetRemainTime1, 1000);
				return false;
			} else if (Message.code == 500) {
				layer.msg('验证码错误');
				//倒计时
				$("#btnSendCode1").attr("disabled", "true");
				$("#btnSendCode1").val(+curCount1 + "秒再获取");
				InterValObj1 = window.setInterval(SetRemainTime1, 1000);
				return false;
			} else {
				// if (Message.msg != null) {
				// 	layer.msg(Message.msg);
				// } else {
				// 	layer.msg('你今天的手机验证码获取上限');

				// }
				//倒计时
				$("#btnSendCode1").attr("disabled", "true");
				$("#btnSendCode1").val(+curCount1 + "秒再获取");
				InterValObj1 = window.setInterval(SetRemainTime1, 1000);
				return false;
			}
		},
		error: function (data) {
			layer.msg("手机验证码获取异常");
			layer.msg(data);
			return false;
		}
	});







}
function SetRemainTime1() {
	if (curCount1 == 0) {
		window.clearInterval(InterValObj1);//停止计时器
		$("#btnSendCode1").removeAttr("disabled");//启用按钮
		$("#btnSendCode1").val("重新发送");
	} else {
		curCount1--;
		$("#btnSendCode1").val(+curCount1 + "秒再获取");
	}
}
function SubmitDisabled() {
	// 使id=submit的按钮可以点击

	$("#submit").attr("disabled", "false");
}
// 输入验证码展示下面的内容

$(document).ready(function () {
	$('#code').on('input', function () {
		var codeValue = $(this).val(); // 获取input的当前值
		if (codeValue.length == 6) { // 如果codeValue有值（非空字符串）
			$("#divShow").show();
		}
	});
});
/*提交*/
function submitForm() {

	var zz = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
	var mobile = $('#mobile').val();
	var code = $('#code').val();
	var city = $('#selCity').find("option:selected").text();
	var selProvince = $('#selProvince').find("option:selected").text();
	var city_id = $('#selCity').val();
	var page_id = $('#page_id').val();
	var url = window.location.href;
	var name = $('#name').val();
	var money = $('#amount').val();
	var age = $('#age').val();
	var sex = $('#sex').val();
	var nx = $('#nx').val(); //年限
	var company = $('#company').val(); //单位性质
	var product_line = $('#product_line').val();
	var remark = '';
	remark = '资金需求:' + money;
	if (city_id == '' || city == '请选择所在城市') {
		layer.msg("请选择城市");
		return false;
	}
	if (mobile == '') {
		layer.msg("填写手机号");
		return false;
	}
	if (code == '') {
		layer.msg("请填写验证码");
		return false;
	}
	if (code.length != 6) {
		layer.msg("请填写正确6位数验证码");
		return false;
	}
	if (name == '') {
		layer.msg("姓名为必填！");
		return false;
	}
	//公积金
	var quota = $('#quota').val();//公积金额度

	if (quota == '') {
		layer.msg("请完善公积金缴存额度");
		return false;
	}
	if (money == '') {
		layer.msg("请选择您的需求金额！");
		return false;
	}
	if (nx == '') {
		layer.msg("请选择缴纳时间");
		return false;
	}
	if (company == '') {
		layer.msg("请选择单位性质");
		return false;
	}

	remark = "公积金---" + '资金需求:' + money + ',年限:' + nx  + "单位性质："+ company;
	if (!$('#myCheck').get(0).checked) {
		layer.msg("请勾选同意用户协议！");
		return false;
	}
// 判断city_id是否有横杠如果有就去掉
    if (city_id.indexOf('-')!= -1) {
        city_id = city_id.substring(0, city_id.indexOf('-'));
    }

	if (zz.test(mobile)) {
		// 使id=submit的按钮不能点击
		$('.btn1').attr("disabled", "disabled");
		// $("#submit").attr("disabled", "true");
		// $.ajax({
		// 	type: "GET",                      //请求类型
		// 	url: 'http://lzdapi.zazx.info/other/check_apply_code02.html?mobile=' + mobile + '&smscode=' + code,
		// 	jsonp: "callback",
		// 	dataType: "json",                 //返回的数据类型
		// 	contentType: "application/x-www-form-urlencoded",
		// 	success: function (Message) {
		// 		if (Message.status == 1) {


		$.ajax({
			type: "POST",                      //请求类型
			url: 'https://api.rxb.ink/BridgeJoint/common/send_json/apitoapi', //URL
			data: JSON.stringify({
				type: 3,
				channelId: 62,
				product_line: product_line,
				mobile: mobile,
				city: city_id,
				city_id: city_id,
				code: code,
				page_id: page_id,
				// url: url,
				sex: sex,
				remark: remark,
				username: name,
				money: money,
				quota: money,
				api_url: "/api/pushsec/wailian",
				isGjj: true

			}),
			dataType: "json",        //返回的数据类型
			contentType: "application/json",             //返回的数据类型
			success: function (data) {
				var Msg = data
				if (Msg.code == 200) {
					if (Msg.corpId !== 310) {
						_baq.track("form", { assets_id: "1801639325206537" })
					}
					layer.msg('提交成功，2小时内会有业务人员联系您！');
					setTimeout(function () {
						// wenxin();  //温馨提示
						// location.reload();
						clearInfo();
					}, 3000);
					$('.btn1').attr("disabled", "disabled");
					pushLog();
				} else if (Msg.code == 201 && Msg.msg == "code error") {
					layer.msg('验证码有误！');
					$('.btn1').removeAttr("disabled");
					return false;
				} else if (Msg.code == 202) {
					layer.msg('手机号已被其他客户使用！');
					$('.btn1').removeAttr("disabled");

				} else {
					layer.msg('系统繁忙，请稍后再试');
					setTimeout(function () {
						// location.reload();
						clearInfo();
					}, 3000);
				}
			},
			error: function (data) {
				$('#submit').attr('onClick', 'submitForm()');
				layer.msg('提交失败',);
				return false;
			}
		});

	} else {
		// SubmitDisabled
		layer.msg("手机号码格式错误");
		return false;
	}
}
function clearInfo() {
	document.getElementById('myForm').reset();
}

function pushLog() {
	$.ajax({
		type: "POST",                         //请求类型
		url: sms_url + "/cusCount/pushLog", //URL
		data: JSON.stringify({
			"social": 66062,
			"urlNo": 62
		}),
		dataType: "json",                 //返回的数据类型
		contentType: "application/json",
		success: function (msg) {
			console.log(msg.code)
		}
	});
}


